package com.example.administrator.jingpingou.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.jingpingou.R;
import com.example.administrator.jingpingou.bean.NextThemeBean;

import org.xutils.x;

import java.util.List;

/**
 * Created by lenovo on 2016/8/29.
 */
public class NextThemeAdapter extends RecyclerView.Adapter<NextThemeAdapter.MyViewHolder> {
    private Context mContext;
    private List<NextThemeBean.DataBean> mData;
    private View.OnClickListener   mListener;
    public NextThemeAdapter(List<NextThemeBean.DataBean> data,Context context){
        mData =data;
        mContext=context;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_activity_next_theme_one,null);
        MyViewHolder holder = new MyViewHolder(view);
        return holder;
    }

    public void setOnItemClickListener(View.OnClickListener listener){
        mListener=listener;
    }
    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        NextThemeBean.DataBean dataBean = mData.get(position);
        holder.mTextViewSale.setText(dataBean.getDiscount()+" 折");
        holder.mTextViewOldPri.setText(dataBean.getOrigin_price());
        holder.mTextViewPri.setText(dataBean.getNow_price());
        holder.mTextViewCon.setText(dataBean.getTitle());

        x.image().bind(holder.mImageView,dataBean.getPic_url());
        if (mListener!=null) {
            holder.mImageView.setTag(position);
            holder.mImageView.setOnClickListener(mListener);
        }
    }

    @Override
    public int getItemCount() {
        return mData==null?0:mData.size();
    }


    public static class MyViewHolder extends RecyclerView.ViewHolder{
        private ImageView mImageView;
        private TextView mTextViewPri,mTextViewOldPri,mTextViewCon,mTextViewSale;
        public MyViewHolder(View itemView) {
            super(itemView);
            mImageView = (ImageView) itemView.findViewById(R.id.iv_item_act_next_theme_one);
            mTextViewCon = (TextView) itemView.findViewById(R.id.tv_item_next_theme_one_con);
            mTextViewOldPri = (TextView) itemView.findViewById(R.id.tv_item_ac_next_theme_one_oldpri);
            mTextViewPri = (TextView) itemView.findViewById(R.id.tv_item_ac_next_theme_one_pri);
            mTextViewSale = (TextView) itemView.findViewById(R.id.tv_item_ac_next_theme_one_sale);
        }
    }
}
